package com.sise.cn.controller;

import com.sise.cn.annotation.AccessAuthority;
import com.sise.cn.api.common.service.BaseOrderHandler;
import com.sise.cn.api.common.service.OrderAssociateItemHandler;
import com.sise.cn.api.his.po.TicketOrderPO;
import com.sise.cn.api.his.service.TicketService;
import com.sise.cn.task.service.impl.MessageSend;
import com.sise.cn.task.vo.ServerResponseVO;
import com.sise.cn.utils.SpringContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 龚秀峰
 * @version 1.0
 * @date 2020/6/14 17:01
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Resource
    private TicketService ticketService;
    @Resource
    private MessageSend messageSend;


    @AccessAuthority
    @GetMapping("/testGet")
    public ServerResponseVO<Object> getOrderById(@RequestParam(value = "id") Long id) {
        return ServerResponseVO.success(ticketService.getOrderById(id));
    }

    @AccessAuthority
    @PostMapping("/testPost")
    public ServerResponseVO<Object> addOrder(@RequestBody TicketOrderPO order) {

        return ServerResponseVO.success(ticketService.saveOrder(order));
    }

    @AccessAuthority
    @PutMapping("/testPut")
    public ServerResponseVO<Object> updateOrder(@RequestBody TicketOrderPO order) {
        ticketService.updateOrderByOrderCode(order);
        return ServerResponseVO.success();
    }

    @AccessAuthority
    @DeleteMapping("/testDelete")
    public ServerResponseVO<Object> deleteOrderByOrderCode(@RequestParam(value = "id") Long id) {
        ticketService.deleteOrderById(id);
        return ServerResponseVO.success();
    }

    @AccessAuthority
    @GetMapping("/testProcess")
    public ServerResponseVO<Object> aOrderByOrderCode(@RequestParam(value = "id") Long id) {
        BaseOrderHandler orderAssociateHandler = SpringContext.getBeanByType(OrderAssociateItemHandler.class);
        final TicketOrderPO ticketOrderPO = new TicketOrderPO();
        ticketOrderPO.setId(id);
        orderAssociateHandler.processOrder(ticketOrderPO);
        return ServerResponseVO.success();
    }
}
